<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="项目部" prop="projectDepartment.id"
                :rules="[
                 ]">
          <SelectTree
                      ref="projectDepartment"
                      :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }"

                      url="/sys/office/treeData?type=2"
                      :value="inputForm.projectDepartment.id"
                      :clearable="true"
                      :accordion="true"
                      @getValue="(value) => {inputForm.projectDepartment.id=value}"/>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="施工队负责人" prop="constructionTeamLeader.id"
                :rules="[
                 ]">
                <user-select :limit='1' :value="inputForm.constructionTeamLeader.id" @getValue='(value) => {inputForm.constructionTeamLeader.id=value}'></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="施工人员具体信息" prop="constructorDetail.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择施工人员具体信息"
            labelName = 'name'
            labelValue = 'id'
            :value = "inputForm.constructorDetail.id"
            :limit="1"
            @getValue='(value) => {inputForm.constructorDetail.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'name',
              label: '姓名'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'name',
              label: '姓名'
            }
            ]"
            dataListUrl="/epc.labor/constructordetail/constructorDetail/list"
            entityBeanName="constructorDetail"
            queryEntityUrl="/epc.labor/constructordetail/constructorDetail/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="施工队伍类别" prop="constructionTeamType"
                :rules="[
                 ]">
                <el-select v-model="inputForm.constructionTeamType" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('construction_team_type')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="企业名称" prop="companyName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.companyName" placeholder="请填写企业名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="注册地址" prop="RegisteredAddress"
                :rules="[
                 ]">
              <el-input v-model="inputForm.RegisteredAddress" placeholder="请填写注册地址"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="法人代表" prop="corporateRepresentative"
                :rules="[
                 ]">
              <el-input v-model="inputForm.corporateRepresentative" placeholder="请填写法人代表"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="营业执照号码" prop="businessLicenseNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.businessLicenseNumber" placeholder="请填写营业执照号码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="营业执照有效期" prop="termBusinessLicense"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.termBusinessLicense"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="税务登记证号" prop="taxRegistrationCertificateNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.taxRegistrationCertificateNumber" placeholder="请填写税务登记证号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="注册资金" prop="registeredCapital"
                :rules="[
                 ]">
              <el-input v-model="inputForm.registeredCapital" placeholder="请填写注册资金"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="资质等级" prop="qualificationLevel"
                :rules="[
                 ]">
              <el-input v-model="inputForm.qualificationLevel" placeholder="请填写资质等级"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="资质证书号码" prop="certificateNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.certificateNumber" placeholder="请填写资质证书号码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="安全生产许可证号码" prop="productionSafetyLicenseNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.productionSafetyLicenseNo" placeholder="请填写安全生产许可证号码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="安全生产证有效期" prop="productionSafetyCertificateTerm"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.productionSafetyCertificateTerm"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="开户许可证号码" prop="accountOpeningLicenseNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.accountOpeningLicenseNo" placeholder="请填写开户许可证号码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="一般纳税人资格证" prop="generalTaxpayerQualificationCertificate"
                :rules="[
                 ]">
              <el-input v-model="inputForm.generalTaxpayerQualificationCertificate" placeholder="请填写一般纳税人资格证"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="经营范围" prop="businessScope"
                :rules="[
                 ]">
              <el-input v-model="inputForm.businessScope" placeholder="请填写经营范围"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="意外伤害保险人数" prop="accidentInsuranceNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.accidentInsuranceNumber" placeholder="请填写意外伤害保险人数"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="意外伤害保险有效日期" prop="accidentInsuranceTrem"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.accidentInsuranceTrem"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="协作部门" prop="departmentCollaboration.id"
                :rules="[
                 ]">
          <SelectTree
                      ref="departmentCollaboration"
                      :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }"

                      url="/sys/office/treeData?type=2"
                      :value="inputForm.departmentCollaboration.id"
                      :clearable="true"
                      :accordion="true"
                      @getValue="(value) => {inputForm.departmentCollaboration.id=value}"/>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import SelectTree from '@/components/treeSelect/treeSelect.vue'
  import UserSelect from '@/components/userSelect'
  import GridSelect from '@/components/gridSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          projectDepartment: {
            id: ''
          },
          constructionTeamLeader: {
            id: ''
          },
          constructorDetail: {
            id: ''
          },
          constructionTeamType: '',
          companyName: '',
          RegisteredAddress: '',
          corporateRepresentative: '',
          businessLicenseNumber: '',
          termBusinessLicense: '',
          taxRegistrationCertificateNumber: '',
          registeredCapital: '',
          qualificationLevel: '',
          certificateNumber: '',
          productionSafetyLicenseNo: '',
          productionSafetyCertificateTerm: '',
          accountOpeningLicenseNo: '',
          generalTaxpayerQualificationCertificate: '',
          businessScope: '',
          accidentInsuranceNumber: '',
          accidentInsuranceTrem: '',
          departmentCollaboration: {
            id: ''
          },
          remarks: ''
        }
      }
    },
    components: {
      SelectTree,
      UserSelect,
      GridSelect
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建施工协作队伍信息管理`
        } else if (method === 'edit') {
          this.title = '修改施工协作队伍信息管理'
        } else if (method === 'view') {
          this.title = '查看施工协作队伍信息管理'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/epc/labor/constructionteam/constructionTeam/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.constructionTeam)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/epc/labor/constructionteam/constructionTeam/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>